<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ include file="/pages/include.jsp"%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<style>
		a{ text-decoration:none; color : blue; }
	</style>
	<script type="text/javascript">
	var operateObj = {};
	$(function() {
		//初始化工作流类型
		$("#phoneType").combobox({
			url: "<%=path%>/dictionary/getPhoneType",
			valueField : "id",
			textField : "text",
			panelHeight : "auto",
			required:true,    
		    multiple:false,
		    onSelect: function(rec){    
	            loadDetailType(rec);   
	        }
		});
		
		$("#repairType").combobox({
			url: "<%=path%>/common/loadDictCombobox?dictCode=repairType",
			valueField : 'dictDetailCode',
		    textField : 'dictDetailName',
		    panelHeight : "auto",
			required:true,    
		    multiple:false
		});
		
		//查询
		$('#search-form').linkbutton({
			text:'查询',
			iconCls: 'icon-search',
			onClick: function(){
				$('#phonePriceGrid').datagrid('load',{
					
					phoneType : $("#phoneType").combobox("getValue"),
					detailType: $("#detailType").combobox("getValue"),
					repairType: $("#repairType").combobox("getValue")
				});
			}
		});
		
		//重置查询表单
		$('#clear-form').linkbutton({
			text:'重置',
			iconCls: 'icon-clear',
			onClick: function(){
				//清空查询文本框的值
				$("#phoneType").combobox("setValue","");
				$("#detailType").combobox("setValue","");
				$("#repairType").combobox("setValue","");
				//重新发送一遍请求
				$('#phonePriceGrid').datagrid('load',{});
				
			}
		});
		
		//新增价格
		$('#add-phone').linkbutton({
			text:'新增',
			iconCls: 'icon-add',
			onClick: function(){
				operationForm("add");	
			}
		});
		
		//修改价格
		$('#edit-phone').linkbutton({
			text:'修改',
			iconCls: 'icon-edit',
			onClick: function(){
				operationForm("edit");	
			}
		});
		
		//删除价格
		$('#del-phone').linkbutton({
			text:'删除',
			iconCls: 'icon-remove',
			onClick : function(){
				$.messager.confirm("操作提示", "您确定要执行操作吗？", function (data) {
					if (data) {
						$.ajax({
							url : '<%=path%>/price/delPhonePrice',
							data : { phonePriceId : operateObj.priceId },
							success : function(json){
								var json = eval('(' + json + ')');
								$.messager.alert('提示', json.message);
								$('#phonePriceGrid').datagrid();
							}  
						});
					}
				});
			}
		});
		
		//Grid填充
		$("#phonePriceGrid").datagrid({
			url : '<%=path%>/price/queryPrice',
			pagination : true,
			pageSize : 20,
			pageNumber : 1,
			fit: true, //datagrid自适应宽度
	        fitColumns: true, //列自适应宽度
	        striped: true, //行背景交换
	        idField: 'priceId', //主键
	        singleSelect : true,
	        queryParams : {
	        	
	        },
	        frozenColumns : [ [ {
				field : 'id',
				width : 10,
				align : 'center',
				checkbox : true
			} ] ],
	        onSelect : function(rowIndex, rowData){
				operateObj = rowData;
				$('#edit-phone').linkbutton('enable');
				$('#del-phone').linkbutton('enable');
			},
			onLoadSuccess : function(data){
				$('#edit-phone').linkbutton('disable');
				$('#del-phone').linkbutton('disable');
			},
			toolbar : '#controlTasktoolbar',
				columns : [ [
					{
						field : 'priceId',
						title : '项目名称',
						width : 100,
						align : 'center',
						hidden : 'true'
					},{
						field : 'pricePhoneText',
						title : '手机品牌',
						width : 100,
						align : 'center'
					},{
						field : 'priceDetailText',
						title : '手机型号',
						width : 100,
						align : 'center'
					},{
						field : 'priceRepairText',
						title : '损坏类别',
						width : 100,
						align : 'center'
					},{
						field : 'repairPrice',
						title : '维修价格',
						width : 130,
						align : 'center'
					}
			 ] ]
		});
	});
	
	function operationForm(operationType){
		var title = "新增";
		var url = '<%=path%>/pages/price/addPrice.jsp';
		if(operationType == "edit"){
			title = "修改";
			url = '<%=path%>/pages/price/addPrice.jsp';
		}else{
			operateObj = {};
		}
		
		$('#dlg').dialog({
			modal : true,
			title : title,
			width : document.body.clientWidth * 0.3,
			height : document.body.clientHeight * 0.6,
			top : $(document).scrollTop() + document.body.clientHeight * 0.1,
			cache: false,
			href : url, 
			buttons : [
				{text:'保存',handler:function(){sbumitform();}},
				{text:'取消',handler:function(){
					$('#dlg').dialog('close');
					$("#dlg").dialog('destroy');
				}}
			]
		});
		
	}
	
	function sbumitform(){
		$('#addjpdl').form('submit',{  
			method : 'post',
			url : '<%=path%>/price/savePhonePrice',
			success : function(json){  
				var json = eval('(' + json + ')');
				$.messager.alert('提示', json.message);
				if(json.result){
					$('#dlg').dialog('close');
					$('#phonePriceGrid').datagrid();
				}
			} 
		});
	}
	function loadDetailType(rec){
		$("#detailType").combobox({
			url: "<%=path%>/dictionary/getPhoneDetailType?dictId=" + rec.id,
			valueField : "id",
			textField : "text",
			panelHeight : "auto",
			required:true,    
		    multiple:false
		});
	}
	</script>
</head>
<body>
	<div id="dlg">
		<div id="add" class="easyui-panel" ></div>
	</div>
	<div id="controlTasktoolbar">
		<div id="tobar" style="margin-left: 5px;">
			<button id="add-phone">新增</button>
			<button id="edit-phone">修改</button>
			<button id="del-phone">删除</button>
			手机品牌：<input id="phoneType" class="easyui-combobox" style="width:140px;"></input>&nbsp;|
			手机型号：<select id="detailType" class="easyui-combobox" style="width:140px;"></select>&nbsp;|
			维修类型：<select id="repairType" class="easyui-combobox" style="width:140px;">&nbsp;|&nbsp;
			维修类型：<select id="3333" class="easyui-combobox" style="width:150px;">&nbsp;|&nbsp;
			<button id="search-form">查询</button>
			<button id="clear-form">重置</button>
		</div>
	</div>
	<div id="phonePriceGrid" style="height: 90%"></div>
</body>
</html>
